opendir
打开目录句柄
opendir() 函数打开目录句柄。
打开一个目录,读取它的内容,然后关闭:
<?php
$dir = "/images/";
// 打开目录,然后读取其内容
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
closedir($dh);
}
}
?>
结果:
filename: cat.gif filename: dog.gif filename: horse.gif
opendir(path,context);
| 参数 | 描述 |
|---|---|
| path | 必需。规定要打开的目录路径。 |
| context | 可选。规定目录句柄的环境。context 是可修改目录流的行为的一套选项。 |